package com.etc.service.impl;

import com.etc.dao.OrderDao;
import com.etc.entity.Orders;
import com.etc.service.OrderService;
import org.apache.ibatis.annotations.Param;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderDao orderDao;

    /**
     * 新增订单（下单）
     * @param
     * @return
     * @author 赵伟伟
     */
    @Override
    public boolean addOrder(@Param("bId") Integer bId,
                            @Param("oTitle") String oTitle,
                            @Param("oNum") Integer oNum,
                            @Param("totalFee") double totalFee,
                            @Param("oImg") String oImg) {

        return orderDao.addOrder(bId,oTitle,oNum,totalFee,oImg)== 0 ? false:true;
    }


    @Override
    public PageInfo<Orders> getOrders(String oTitle, int pageNum, int size) {
        PageHelper.startPage(pageNum, size);
        List<Orders> list = orderDao.queryOrders("%" + oTitle + "%");
        PageInfo<Orders> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Orders> updateOrders(Integer oStatus, String oId, String oTitle,int pageNum, int size) {
        int i = orderDao.updateOrders(oStatus, oId);
        PageInfo<Orders> pageInfo = getOrders(oTitle, pageNum, size);
        return pageInfo;
    }

    /**
     * 查询所有订单
     * @return 订单集合
     * @author 赵伟伟
     *
     */
    @Override
    public List<Orders> getAllOrders() {

        return orderDao.queryAllOrders();
    }

    /**
     * 根据定案编号查询订单信息
     * @return 订单对象
     * @author 赵伟伟
     */
    @Override
    public Orders getOrdersById(String oId) {
        return orderDao.queryById(oId);
    }

    /**
     * 根据订单编号删除订单
     * @param oId 订单编号
     * @return true:删除成功，false：删除失败
     * @author 赵伟伟
     */
    @Override
    public boolean delById(String oId) {

        return orderDao.delById(oId) == 0 ?false:true;
    }
}
